// pkgArticle/pages/detail/detail.js
const date = require('../../../utils/util')
Page({

  /**
   * 页面的初始数据
   */
  data: {
     date:'',
     detail:{},
     hotList:[],
     Id:'',
     isCollect:'add',
     likeData:'like-o',
     islove:'add',
     loveData:'thumb-circle-o',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
   this.getListDetail(options.id)
   this.data.Id = options.id
  },

 async clickLove(){
 
  // 点赞
  const res = await wx.http.get('/user/userDataHandle',{
    type:'2',article_id:this.data.Id,action:this.data.islove
  })
  console.log(res);
  if(this.data.loveData === 'thumb-circle-o'){
    // this.data.loveData = 'love'
    this.setData({loveData:'thumb-circle'})
    this.data.islove = 'del'
     wx.utils.toast('点赞成功')
  }else{
    // this.data.loveData = 'love-o'
    this.setData({loveData:'thumb-circle-o'})
    this.data.islove = 'add'
    wx.utils.toast('取消点赞')
  }
},
  

// 分享
onShareAppMessage(ev) {
  console.log(ev);
  // 获取加密数据

  return {
    title: '文章详情',
    path: '',
    imageUrl: 'http://124.223.14.236:8060/upload/images/20230709/1688890519470.jpg',
  }
},



async clickcolllet(ev){
  console.log(ev);
// 收藏
const res = await wx.http.get('/user/userDataHandle',{
    type:'1',article_id:this.data.Id,action:this.data.isCollect
  })
  console.log(res);
  if(this.data.likeData === 'like-o'){
    // this.data.likeData = 'like'
    this.setData({likeData:'like'})
    this.data.isCollect = 'del'
    wx.utils.toast('收藏成功')
  }else{
    // this.data.likeData = 'like-o'
    this.setData({likeData:'like-o'})

    this.data.isCollect = 'add'
    wx.utils.toast('取消收藏')
  }
},


 async getListDetail(id){
    const data = await wx.http.get('/index/show?id='+id)
    console.log(data);
    // this.detail = data.data.info
    this.setData({hotList:data.data.recommend}) 
    this.setData({detail:data.data.info})
    this.setData({date:date.formatTime(this.data.detail.create_date,'yy/mm/dd')})
  },


})